Passed
Pull Request — master (#220)
by
unknown
02:04
created

ArrayUtils   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 20
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A range 0 10 3
A flatMap 0 7 2
1
export class ArrayUtils {
2
  public static range(start: number, end: number, step: number = 1) {
3
    function* generateRange() {
4
      let x = start - step;
5
      while (x <= end - step) {
6
        yield (x += step);
7
      }
8
    }
9
10
    return {
11
      [Symbol.iterator]: generateRange
12
    };
13
  }
14
15
  public static flatMap<T, V>(items: T[], fn: (x: T) => V[]): V[] {
16
    const arr = [];
17
    for (let item of items) {
18
      arr.push(...fn(item));
19
    }
20
    return arr;
21
  }
22
}
23